Partial Class pages_Payments_Payment : Inherits CPage

#Region "Querystring"
    Public ReadOnly Property PaymentId() As Integer
        Get
            Dim id As Integer = CWeb.RequestInt("paymentId")
            If id = Integer.MinValue Then CSitemap.RecordNotFound("Payment", id)
            Return id
        End Get
    End Property
#End Region

#Region "Members"
    Private m_payment As CPayment
#End Region

#Region "Data"
    Public ReadOnly Property [Payment]() As CPayment
        Get
            If IsNothing(m_payment) Then
                Try
                    m_payment = New CPayment(PaymentId)
                Catch
                    CSitemap.RecordNotFound("Payment", PaymentId)
                End Try                   
            End If
            Return m_payment
        End Get
    End Property
#End Region

#Region "Event Handlers - Page"
    Protected Overrides Sub PageLoad()
        With Me.Payment
            txtPaymentCreated.ToolTip = CUtilities.LongDateTime(.PaymentCreated)
            txtPaymentCreated.Text = CUtilities.Timespan(.PaymentCreated)

            txtPaymentTransaction.Text = .PaymentTransaction
            chkPaymentIsOk.Value = .PaymentIsOk
            txtPaymentCode.Text = .PaymentCode

            txtPaymentFirstName.Text = .PaymentFirstName
            txtPaymentLastName.Text = .PaymentLastName
            txtPaymentItemName.Text = .PaymentItemName


            txtPaymentCurrency.Text = .PaymentCurrency
            txtPaymentAmount.ValueMoney = .PaymentAmount
            txtPaymentFee.ValueMoney = .PaymentFee
            txtPaymentNet.ValueMoney = .PaymentNet

            lnkPaymentOrderId.Text = String.Concat("#", .PaymentOrderId.ToString, " (", CUtilities.Timespan(.OrderCreated), ")")
            If Integer.MinValue = .PaymentOrderId Then
                lnkPaymentOrderId.Text = "Donation"
                lnkPaymentOrderId.Enabled = False
            End If
            lnkPaymentOrderId.NavigateUrl = CSitemap.Order(.PaymentOrderId)
            lnkProductId.Text = .ProductName
            lnkProductId.NavigateUrl = CSitemap.ProductEdit(.OrderProductId)

            txtPaymentMemo.Text = .PaymentMemo

            Try
                Dim dict As Dictionary(Of String, String) = CPayment.Split(.PaymentDetails)
                Dim keys As New List(Of String)(dict.Keys)
                keys.Sort()
                For Each i As String In keys
                    Dim tr As New HtmlTableRow
                    tbl.Rows.Add(tr)
                    If keys.IndexOf(i) Mod 2 = 0 Then tr.Attributes.Add("class", "alt_row")

                    Dim td As New HtmlTableCell
                    tr.Cells.Add(td)
                    td.InnerText = i

                    td = New HtmlTableCell
                    tr.Cells.Add(td)
                    td.InnerText = dict(i)
                Next
            Catch ex As Exception
                Dim tr As New HtmlTableRow
                tbl.Rows.Add(tr)

                Dim td As New HtmlTableCell
                tr.Cells.Add(td)
                td.ColSpan = 2
                td.InnerText = ex.Message
            End Try
        End With
    End Sub
#End Region

End Class
